#include <stdio.h>
#include <iostream>
#include "ThreadPool.h"

using namespace std;
using namespace boost::asio;
using namespace tsc::common;

void printStatus()
{
  FILE *fp;
  char path[1035];

  /* Open the command for reading. */
  fp = popen("ps H -eT | grep testThreadPool", "r");
  if (fp == NULL)
  {
    printf("Failed to run command\n" );
    return;
  }

  /* Read the output a line at a time - output it. */
  while (fgets(path, sizeof(path)-1, fp) != NULL)
  {
    printf("%s", path);
  }

  /* close */
  pclose(fp);

  return;
}

int main(int argc, char* argv[])
{
  io_service* pIoService = 0;

  cout << "Add io_service \n";
  pIoService = ThreadPool::instance()->addIoService();
  cout << "Add io_service \n";
  pIoService = ThreadPool::instance()->addIoService();

  printStatus();

  cout << "start io_service \n";
  ThreadPool::instance()->startIoServices();

  printStatus();

  cout << "stop io_service \n";
  ThreadPool::instance()->stopIoServices();

  printStatus();

  cout << "done\n";
}
